package com.heima.xxljob.job;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.juli.logging.Log;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class HelloJob {


    @XxlJob("demoJobHandler")
    public void helloJob() {
        System.out.println("简单任务执行了。。。。");
    }

    @XxlJob(value = "jobdemo")
    public void helloJob2() {
        int shardIndex = XxlJobHelper.getShardIndex();//分片索引
        int shardTotal = XxlJobHelper.getShardTotal();//分片总数
        for (int i = 0; i < 10000; i++) {
            if (i % shardTotal == 0) {
                log.info("当前分片索引为" + shardIndex + "执行了第" + i + "个任务");
            }
        }
    }
}